Skip to content

Conversation

@JHZLO
Copy link

@JHZLO JHZLO commented Dec 4, 2025

Problem

When using a custom template for Slack alert notifications, both the default template fields (Query/Alert links) AND the custom template are displayed together.

Current behavior:

Query: /queries/123
Alert: /alerts/9
Description: [custom template content]

Expected behavior:
When custom_body is set, only the custom template should be displayed.

Root Cause

The Slack destination uses append() to add custom_body to the existing fields instead of replacing them:

fields = [
    {"title": "Query", ...},
    {"title": "Alert", ...},
]
if alert.custom_body:
    fields.append({"title": "Description", "value": alert.custom_body})  # appends instead of replaces

Solution

Restructure the notification logic:

  • If custom_body is set → send only the custom template
  • If custom_body is not set → send default template (existing behavior)

@yoshiokatsuneo
Copy link
Contributor

@JHZLO

I think you need to run the DB migration scripts to add the selector field after upgrading.
Have you run migration script like below ?

docker compose run --rm server manage db upgrade

Thank you.

@JHZLO
Copy link
Author

JHZLO commented Dec 6, 2025

@yoshiokatsuneo
Thanks for the response!

This is not a migration issue.
When creating an alert via the UI, Redash stores the column name as options.column, but render_template() tries to access self.options["selector"], which causes KeyError.

@yoshiokatsuneo
Copy link
Contributor

@JHZLO

Thank you.
So, in you case, is the selector specified at alert setting UI below stored as options field on the DB ?

image

When a custom template is configured for an alert, the Slack destination
was appending the custom_body to the default fields (Query/Alert links)
instead of replacing them. This resulted in both default and custom
templates being displayed together.

This fix restructures the notification logic:
- If custom_body is set: send only the custom template
- If custom_body is not set: send default template (existing behavior)
@JHZLO JHZLO force-pushed the fix/slack-custom-template-notification branch from bb6f00f to f370589 Compare December 7, 2025 05:28
@JHZLO
Copy link
Author

JHZLO commented Dec 7, 2025

@yoshiokatsuneo
I apologize for my initial response. You were right.

I'm not sure exactly what triggered it, but until lastweek the selector key was not being added (I suspect it was the Helm post-upgrade hook that automatically runs DB migrations). When I tested again today and checked the database, I found that the selector key now exists. I confirmed this was resolved by the migration in #7475. Thank you!

However, there's still a valid bug: when using a custom template, both the default template fields (Query/Alert links) AND the custom template are displayed together in Slack notifications.
I'm not sure if this is intentional, but users who set up a custom template would likely expect only their custom template to be sent. The current implementation uses append() to add custom_body to the existing fields, resulting in both being displayed. I've updated this PR to focus only on the Slack destination fix - sending only the custom template when custom_body is set.

@JHZLO JHZLO changed the title fix(alerts): Fix Slack custom template notification issues fix(slack): Send only custom template when custom_body is set Dec 7, 2025
@yoshiokatsuneo
Copy link
Contributor

yoshiokatsuneo commented Dec 8, 2025

@JHZLO

Thank you for your comment.
I'm not sure what is the best solution.

As, this PR make it possible to skip Query/Alert part.
But, this PR make it impossible to show Query/Alert field as it is now.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants